/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Comunicacion;

import java.util.Vector;

/**
 *
 * @author michael
 */
public class MailBoxFactory {

    private static MailBoxFactory instance = null;

    private Vector<MailBox> mailBoxes;

    public static MailBoxFactory getInstance(){
        if(instance == null){
            instance = new MailBoxFactory();
            return instance;
        }else{
            return instance;
        }
    }
    private MailBoxFactory(){
        mailBoxes = new Vector<MailBox>();
    }

    public MailBox getMailBox(String name) {
        for(int i=0;i<mailBoxes.size();i++){
            if(mailBoxes.get(i).getName().equals(name)){
                return mailBoxes.get(i);
            }
        }
        return createMailBox(name);
    }

    private MailBox createMailBox(String name){
        MailBox actual = new MailBox(name);
        mailBoxes.add(actual);
        return actual;
    }

}
